namespace Example.Models
{
    using System;
    using System.Xml.Serialization;
    using SimpleWebServices;
    using SimpleWebServices.Configuration;
    using SimpleWebServices.Data;
    using SimpleWebServices.Models;
    using SimpleWebServices.Web.UI.Html;

    [XmlRoot("container")]
    public sealed class LogOnForm : FormContainer
    {
        public override void Complete(FormSession session)
        {
            if (null == session)
            {
                throw new ArgumentNullException("session");
            }

            AbsoluteUri urn = new AbsoluteUri("urn://user/" + session.Data["email"].ToLowerInvariant());
            Record.Retrieve<RegisteredUser>(urn).SetAuthenticationCookie<RegisteredUser>(false);

            session.Data.Completed = true;
            session.Store();
        }

        public override T Template<T>()
        {
            return new Default().Object<T>();
        }
    }
}